
//验证
function validateAction(){
	
	//validate the form	  	  
    if(!validateRegion($j("#regionForm").get(0)) ){
    	return false;
   	}
    return true;
}
//保存
function saveRegion(){
	var treeItem=getCategoryItemJSON(jCategoryTree.getSelected());
	if((!treeItem)||!validateAction()){
    	return ;
    }
     var entityName=$j("#regionName").val();
   	if(confirm( __FMT.common_message_confirmSaveThis+entityName+"?")){
    	var postData = $j('#regionForm :input').serialize();
    	var url=$j('#regionForm').attr('action')+"?doAction=save";
    	$j.post(url,postData,saveRegionCallback,"json");
   	}
   	return false;
}

//保存callback
function saveRegionCallback(data){
	if(data.error && data.error!=""){
		jAlert(data.error);
		return ;
	}
 	//保存成功
 	if($j("#regionId").val()==""){
 		//case:新增目录
 		$j("#regionId").val(data.regionId);
 		addCategoryItemToTree(jCategoryTree,data.regionId,data.regionName,data.regionName);
 	}else{
 		//case:编辑目录
 		var jNode = jCategoryTree.getSelected();
 		jNode.find('span:first').html(data.regionName);
 	}
	setTimeout("sysMsg('"+__FMT.regionDetail_save_successed+"')",0);
	
	displayButtons(""+data.regionId);
   
}



